package ystp.service;


import org.springframework.stereotype.Service;
import ystp.dao.KangjunyaowuMapper;
import ystp.model.Kangjunyaowu;
import ystp.model.KangjunyaowuExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class KangjunyaowuService {

    @Resource
    KangjunyaowuMapper ddMapper;

    public boolean isexistByxiangmuId(String xiangmuId){
        KangjunyaowuExample mmExample=new KangjunyaowuExample();
        KangjunyaowuExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }

    public Kangjunyaowu findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

    public List<Kangjunyaowu> findAllByXiangmuId(String xiangmuId){
        KangjunyaowuExample mmExample=new KangjunyaowuExample();
        KangjunyaowuExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return ddMapper.selectByExample(mmExample);
    }

    public List<Kangjunyaowu> findByXiangmuIdAndFenlei(String xiangmuId,String mmFenlei){
        KangjunyaowuExample mmExample=new KangjunyaowuExample();
        KangjunyaowuExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId).andFenleiEqualTo(mmFenlei);
        return ddMapper.selectByExample(mmExample);
    }

    public List<Kangjunyaowu> findByXiangmuIdAndFenleiAndGuizebianhao(String xiangmuId,String mmFenlei,String mmGuizebianhao){
        KangjunyaowuExample mmExample=new KangjunyaowuExample();
        KangjunyaowuExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId).andFenleiEqualTo(mmFenlei).andGuizebianhaoEqualTo(mmGuizebianhao);
        return ddMapper.selectByExample(mmExample);
    }

    public List<Kangjunyaowu> findAllByXiangmuIdAndGuizebianhao(String xiangmuId,String guizebianhao){
        KangjunyaowuExample mmExample=new KangjunyaowuExample();
        KangjunyaowuExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId).andGuizebianhaoEqualTo(guizebianhao);
        return ddMapper.selectByExample(mmExample);
    }

    public boolean add (Kangjunyaowu ddKangjunyaowu){
        return ddMapper.insert(ddKangjunyaowu)==1;
    }
    public boolean deleteByxiangmuId(String xiangmuId){
        KangjunyaowuExample mmExample=new KangjunyaowuExample();
        KangjunyaowuExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }
    public List<Map<String, Object>> findPinzhongAll(String ppxiangmuId,String ppdrugname,String ppfenlei,
                                                     String ppjiyao,String pptongguopingjia, String ppzhidaoyuanze,
                                                     String ppjicaiyao,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhongAll(ppxiangmuId,ppdrugname,ppfenlei,ppjiyao,pptongguopingjia,ppzhidaoyuanze,ppjicaiyao,mmStartIndex,ppPageSize);
    }
    public List<Map<String, Object>> findPinguiByPinzhong(String ppxiangmuId,String mmPinzhongOne){
        return ddMapper.findPinguiByPinzhong(ppxiangmuId,mmPinzhongOne);
    }
    public Integer getPinzhongCount(String ppxiangmuId,String ppdrugname,String ppfenlei,
                                    String ppjiyao,String pptongguopingjia, String ppzhidaoyuanze,
                                    String ppjicaiyao,int ppPageIndex, int ppPageSize) {
        Object mmCount = ddMapper.getPinzhongCount(ppxiangmuId,ppdrugname,ppfenlei,ppjiyao,pptongguopingjia,ppzhidaoyuanze,ppjicaiyao,ppPageIndex,ppPageSize);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findPinguiResultByPinzhong(String ppxiangmuId,String ppuserId,String mmPinzhongOne,
                                                                String ppdrugname,String ppfenlei,
                                                                String ppjiyao,String pptongguopingjia, String ppzhidaoyuanze,
            String ppjicaiyao){
        return ddMapper.findPinguiResultByPinzhong(ppxiangmuId,ppuserId,mmPinzhongOne,ppdrugname,ppfenlei,ppjiyao,pptongguopingjia,ppzhidaoyuanze,ppjicaiyao);
    }

    public Integer getVoteCount(String ppxiangmuId){
        List<Map<String, Object>> list=ddMapper.findPinzhongAndPinguiByXiangmuId(ppxiangmuId);
        return list == null ? 0 : list.size();
    }
    public List<Map<String, Object>> findDaochuPinzhongAll(String ppxiangmuId){
        return ddMapper.findDaochuPinzhongAll(ppxiangmuId);
    }

    public List<Map<String, Object>> findFeileiByXiangmuId(String ppxiangmuId){
        return ddMapper.findFeileiByXiangmuId(ppxiangmuId);
    }

    public List<Map<String, Object>> findGuizebianhaoByXiangmuId(String ppxiangmuId){
        return ddMapper.findGuizebianhaoByXiangmuId(ppxiangmuId);
    }
}
